package com.jmpt.fangbohui.ui.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.loopj.android.http.RequestHandle;

import java.util.ArrayList;
import java.util.List;

public class BaseActivity extends FragmentActivity {
    public Context mContext;
    public List<RequestHandle> mRequestHandles;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        mContext = this;
        super.onCreate(savedInstanceState);
    }

    public void addRequestHandle(RequestHandle requestHandle) {
        if (mRequestHandles == null) {
            mRequestHandles = new ArrayList<RequestHandle>();
        }
        mRequestHandles.add(requestHandle);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mRequestHandles != null && mRequestHandles.size() > 0) {
            for (int i = 0; i < mRequestHandles.size(); i++) {
                RequestHandle requestHandle = mRequestHandles.get(i);
                if ((requestHandle.isFinished() || requestHandle.isCancelled()) == false) {
                    requestHandle.cancel(true);
                }
            }
        }
    }
}
